package com.sfac.day03.modules.common.dao;

import com.sfac.day03.modules.common.entity.ExceptionLog;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface ExceptionLogDao {

    @Insert("insert into common_exception_log (create_date, ip, path, class_name, method_name, exception_type, "
            + "exception_message) values (#{createDate}, #{ip}, #{path}, #{className}, #{methodName}, "
            + "#{exceptionType}, #{exceptionMessage})")
    @Options(useGeneratedKeys = true, keyColumn = "id", keyProperty = "id")
    void insertExceptionLog(ExceptionLog exceptionLog);

    @Select("select * from common_exception_log where class_name = #{className} and method_name = #{methodName} "
            + "and exception_type = #{exceptionType} and exception_message = #{exceptionMessage}")
    List<ExceptionLog> getExceptionLogsByParameters(ExceptionLog exceptionLog);
}